home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / CPP100.ZIP / CPPLMAT2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  12.0 KB  |  326 lines

  1. /*****************************************************************************/
  2. /*       (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved         */
  3. /*****************************************************************************/
  4. /*    This source-code is NOT public domain nor Freeware, this is part of    */
  5. /*              'The C Programming Package' which is Shareware.              */
  6. /*   If you use this code, please register and get a free Full-VGA version   */
  7. /*****************************************************************************/
  8.                                /*------------------*
  9.                                 *    CPPLMAT2.C    *
  10.                                 *     Hardware     *
  11.                                 *  config (contd)  *
  12.                                 *------------------*/
  13.  
  14.  /* Included Files */
  15.  # include <stdio.h>
  16.  # include <io.h>
  17.  # include <dos.h>
  18.  # include <fcntl.h>
  19.  # include <bios.h>
  20.  # include <stdlib.h>
  21.  # include <SYS\stat.h>
  22.  # include <conio.h>
  23.  # include <alloc.h>
  24.  # include <process.h>
  25.  # include <ctype.h>
  26.  # include <string.h>
  27.  
  28.  /* Global Variables */
  29.  extern int x,y,z,i,j,k,l,m,n,bm,xm,ym,return2,chx2;
  30.  extern int colour1,colour2,colour3,colour4,colour5,chif,background,colourprov,colourchoice;
  31.  extern unsigned char c1,nc1[],trashcan[];
  32.  
  33.  /*-----------------------*
  34.   * GET COLOURS2 KEYBOARD *
  35.   *-----------------------*/
  36.   int get_colour2_keyboard()
  37.     {
  38.       j=get_key();
  39.       if(j<16){
  40.         /* We entered a legal number between 0 and f/F=15 */
  41.         /* or -1 for <Esc> */
  42.     return(j);
  43.       }
  44.       /* <Enter> confirms the modifications */
  45.       if(c1==13)                       return(21);
  46.       if((c1==66)||(c1==98)){
  47.         /* We want to change the background = B b */
  48.     chx2=1;                        return(21);
  49.       }
  50.       if((c1==70)||(c1==102)){
  51.         /* If we want to change the foreground = F f */
  52.     chx2=2;                        return(21);
  53.       }
  54.       if((c1==67)||(c1==99)){
  55.         /* If we want to confirm the modifications = C c */
  56.     chx2=3;                        return(21);
  57.       }
  58.       if((c1==81)||(c1==113)){
  59.         /* If we want to quit without modifying = Q q */
  60.     chx2=4;                        return(21);
  61.       }
  62.       /* Other cases : return 20 */
  63.       return(20);
  64.     }
  65.  /*----------------------*
  66.   * GET SPECIAL COLOUR 2 *
  67.   *----------------------*/
  68.   int get_special_colour2()
  69.     {
  70.       if(c1==59){
  71.         /* On-line help */
  72.     return(59);
  73.       }
  74.       if(c1==75){
  75.         /* Left arrow */
  76.     if(chx2>1)                     chx2--;
  77.       }
  78.       if(c1==77){
  79.         /* Right arrow */
  80.     if(chx2<4)                     chx2++;
  81.       }
  82.       /* In all the other cases we do not change nothing */
  83.       /* but we return a value                           */
  84.       return(20);
  85.     }
  86.  /*--------------------*
  87.   * GET COLOURS2 MOUSE *
  88.   *--------------------*/
  89.   int get_colour2_mouse()
  90.     {
  91.       if((xm>3)&&(xm<58)&&(ym>5)&&(ym<21)){
  92.         /* We are in the colours zone */
  93.     if((xm>1)&&(xm<10)){
  94.           /* We only change the background colour */
  95.           background=(ym-6)/2;               colourprov=(16*background)+chif;
  96.     }
  97.     if((xm>10)&&(xm<58)){
  98.           /* We are in the colours grid we change both */
  99.           background=(ym-6)/2;               chif=(xm-11)/3;
  100.           colourprov=(16*background)+chif;
  101.     }
  102.       }
  103.       if(ym==22){
  104.         /* With the mouse it is choice and confirmation */
  105.     if((xm>3)&&(xm<16)){
  106.           /* Change the background */
  107.       chx2=1;                      return(21);
  108.     }
  109.     if((xm>16)&&(xm<29)){
  110.           /* Change the chars */
  111.       chx2=2;                      return(21);
  112.         }
  113.           if((xm>29)&&(xm<39)){
  114.           /* Confirm the modifications */
  115.       chx2=3;                      return(21);
  116.     }
  117.     if((xm>39)&&(xm<58)){
  118.           /* Return without change */
  119.       chx2=4;                      return(21);
  120.     }
  121.       }
  122.       /* In all other cases we return 20 */
  123.       return(20);
  124.     }
  125.  /*-----------------------*
  126.   * DISPLAY CHOICE SCREEN *
  127.   *-----------------------*/
  128.   void display_choice_screen()
  129.     {
  130.       hide_the_mouse();
  131.       /* We erase the used zone */
  132.       textattr(15);                    window(2,3,59,24);
  133.       clrscr();                        window(1,1,80,25);
  134.       /* We draw the grid */
  135.       gotoxy(3,3);   cputs("┌──────┬───────────────────────────────────────────────┐");
  136.       gotoxy(3,4);   cputs("│ Back.│             Characters colours                │");
  137.       gotoxy(3,5);   cputs("├──────┼──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┤");
  138.       gotoxy(3,6);   cputs("│   0  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │");
  139.       gotoxy(3,7);   cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
  140.       gotoxy(3,8);   cputs("│   1  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │");
  141.       gotoxy(3,9);   cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
  142.       gotoxy(3,10);  cputs("│   2  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │");
  143.       gotoxy(3,11);  cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
  144.       gotoxy(3,12);  cputs("│   3  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │");
  145.       gotoxy(3,13);  cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
  146.       gotoxy(3,14);  cputs("│   4  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │");
  147.       gotoxy(3,15);  cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
  148.       gotoxy(3,16);  cputs("│   5  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │");
  149.       gotoxy(3,17);  cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
  150.       gotoxy(3,18);  cputs("│   6  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │");
  151.       gotoxy(3,19);  cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
  152.       gotoxy(3,20);  cputs("│   7  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │");
  153.       gotoxy(3,21);  cputs("╠══════╧══╧══╪══╧══╧══╧══╧╤═╧══╧══╧═╤╧══╧══╧══╧══╧══╧══╣");
  154.       gotoxy(3,22);  cputs("║ Background │ Foreground │ Confirm │Quit without modif║");
  155.       gotoxy(3,23);  cputs("╚════════════╧════════════╧═════════╧══════════════════╝");
  156.       gotoxy(3,24);  cputs(" Current  colours.  Your  choice ( Keyboard or Mouse )  ");
  157.       /* Fill it with the value and the colours */
  158.       /* For the background                     */
  159.       trashcan[0]=0x20;                trashcan[1]=0x20;
  160.       trashcan[2]=0x20;                trashcan[3]=0x20;
  161.       trashcan[4]=0x20;                trashcan[5]=0x20;
  162.       trashcan[6]=0x00;
  163.       for(i=1; i<8; i++){
  164.     k=(16*i)+15;                       textattr(k);
  165.         itoa(i,nc1,10);                trashcan[3]=nc1[0];
  166.         gotoxy(4,(2*i)+6);             cputs(trashcan);
  167.       }
  168.       /* And now the foreground */
  169.       trashcan[2]=0x00;
  170.       for(i=0; i<8; i++){
  171.     for(j=0; j<16; j++){
  172.           /* Calculate colour */
  173.       k=(16*i)+j;                  itoa(j,nc1,16);
  174.           /* Transform it in char j to display with right justification */
  175.           trashcan[0]=0x20;            trashcan[1]=nc1[0];
  176.           /* Display it in the right colour */
  177.       textattr(k);
  178.           gotoxy(((3*j)+11),((2*i)+6));   cputs(trashcan);
  179.     }
  180.       }
  181.       show_the_mouse();
  182.     }
  183.  /*--------------------------*
  184.   * DISPLAY CHOICE COLOURS 2 *
  185.   *--------------------------*/
  186.   void display_choice_colour2()
  187.     {
  188.       hide_the_mouse();               textattr(15);
  189.       gotoxy(4,22);                    cputs(" Background ");
  190.       gotoxy(17,22);                   cputs(" Foreground ");
  191.       gotoxy(30,22);                   cputs(" Confirm ");
  192.       gotoxy(40,22);                   cputs("Quit without modif");
  193.       textattr(116);
  194.       gotoxy(5,22);                    cputs("B");
  195.       gotoxy(18,22);                   cputs("F");
  196.       gotoxy(31,22);                   cputs("C");
  197.       gotoxy(41,22);                   cputs("Q");
  198.       /* display this line with the current colours */
  199.       textattr(colourprov);
  200.       gotoxy(3,24);  cputs(" Current  colours.  Your  choice ( Keyboard or Mouse )  ");
  201.       /* Then we outline the choice */
  202.       textattr(112);
  203.       if(chx2==1){
  204.         gotoxy(4,22);              cputs(" Background ");
  205.       }
  206.       if(chx2==2){
  207.     gotoxy(17,22);                 cputs(" Foreground ");
  208.       }
  209.       if(chx2==3){
  210.     gotoxy(30,22);                 cputs(" Confirm ");
  211.       }
  212.       if(chx2==4){
  213.     gotoxy(40,22);                 cputs("Quit without modif");
  214.       }
  215.       show_the_mouse();
  216.     }
  217.  /*--------------------------*
  218.   * COPY NEW VALUE IN COLOUR *
  219.   *--------------------------*/
  220.   void copy_new_value_in_colour()
  221.     {
  222.       if(colourchoice==1)                   colour1=colourprov;
  223.       if(colourchoice==2)                   colour2=colourprov;
  224.       if(colourchoice==3)                   colour3=colourprov;
  225.       if(colourchoice==4)                   colour4=colourprov;
  226.       if(colourchoice==5)                   colour5=colourprov;
  227.     }
  228.  /*-----------------------*
  229.   * LOAD TEMPORARY COLOUR *
  230.   *-----------------------*/
  231.   void load_temporary_colour()
  232.     {
  233.       if(colourchoice==1)                   colourprov=colour1;
  234.       if(colourchoice==2)                   colourprov=colour2;
  235.       if(colourchoice==3)                   colourprov=colour3;
  236.       if(colourchoice==4)                   colourprov=colour4;
  237.       if(colourchoice==5)                   colourprov=colour5;
  238.     }
  239.  /*--------------------------*
  240.   * CHANGE BACKGROUND COLOUR *
  241.   *--------------------------*/
  242.   void change_background_colour()
  243.     {
  244.       textattr(colourprov+128);
  245.       gotoxy(3,24);  cputs(" Enter the new background colour value. Your choice :   ");
  246.       gotoxy(57,24);                   c1=getch();
  247.       z=get_colour2_keyboard();
  248.       if((z>=0)&&(z<8)){
  249.         background=z;                        colourprov=(16*background)+chif;
  250.       }
  251.     }
  252.  /*--------------------------*
  253.   * CHANGE FOREGROUND COLOUR *
  254.   *--------------------------*/
  255.   void change_foreground_colour()
  256.     {
  257.       textattr(colourprov+128);
  258.       gotoxy(3,24);  cputs(" Enter the new foreground colour value. Your choice :   ");
  259.       gotoxy(57,24);                   c1=getch();
  260.       z=get_colour2_keyboard();
  261.       if((z>=0)&&(z<16)){
  262.         chif=z;                        colourprov=(16*background)+chif;
  263.       }
  264.     }
  265.  /*-----------------*
  266.   * CHOOSE A COLOUR *
  267.   *-----------------*/
  268.   void choose_a_colour()
  269.     {
  270.       /* Update the new choice right now */
  271.       display_colour_choice();         display_choice_screen();
  272.       chx2=1;                          load_temporary_colour();
  273.       while(1){
  274.         display_choice_colour2();
  275.     while(1){
  276.       if(kbhit()){
  277.             /* If we pressed a key */
  278.         c1=getch();
  279.         if(c1==0){
  280.               /* The key is coded in 2 bytes. Cut the Second one */
  281.               c1=getch();
  282.               return2=get_special_colour2();  break;
  283.         }
  284.         else{
  285.               /* We pressed a keyboard key */
  286.               return2=get_colour2_keyboard();   break;
  287.         }
  288.       }
  289.           /* Else test the mouse */
  290.           get_mouse_state();
  291.       if(bm==1){
  292.             /* We pressed a mouse button */
  293.             return2=get_colour2_mouse();     break;
  294.       }
  295.     }
  296.         /* We treat the result */
  297.         if(return2==-1)                return;
  298.         if(return2==21){
  299.           /* We confirmed or we pressed <Enter> to confirm */
  300.           if(chx2==1){
  301.             /* We want to change the background colour */
  302.             change_background_colour();
  303.       }
  304.       if(chx2==2){
  305.             /* We want to change the foreground colour */
  306.             change_foreground_colour();
  307.       }
  308.       if(chx2==3){
  309.             /* Return after copying the new color value */
  310.             copy_new_value_in_colour();
  311.         return;
  312.       }
  313.       if(chx2==4){
  314.             /* Return without modifying the colour value */
  315.         return;
  316.       }
  317.     }
  318.         if(return2==22){
  319.           /* F1 = On-line help */
  320.           display_help("CONFIGUR",92,4,1);   restore_help_screen();
  321.     }
  322.       }
  323.     }
  324. /* End of the hardware config file */
  325.  
  326.